﻿using System;
using System.Collections;
using System.Collections.ObjectModel;

namespace HostEdit
{

   
    public class IndexedObservableCollection<T, TKEY> : ObservableCollection<T>
    {


        private Hashtable _Lst = new Hashtable();
        private Func<T, TKEY> _key;


        public IndexedObservableCollection(Func<T, TKEY> key) { _key = key; }


        public new void Add(T item)
        {
            base.Add(item);
            _Lst.Add((TKEY)_key.Invoke(item), item);
        }

        public new void Remove(T item)
        {
            _Lst.Remove((TKEY)_key.Invoke(item));
            base.Remove(item);
        }

        private new void RemoveAt(int index)
        {
            
        }

        public T Get(TKEY key) { return (T)_Lst[key]; }
        public T Get(int index) { return (T)this.Items[index]; }
        public T this[TKEY key] { get { return (T)_Lst[key];} }
        public bool Contains(TKEY key) 
        {
            return _Lst.ContainsKey(key); 
        }

    }

}